import { Component, OnInit } from '@angular/core';
import { AxiosService } from '../../axios.service';


@Component({
  selector: 'app-kufang',
  templateUrl: './kufang.component.html',
  styleUrls: ['./kufang.component.scss']
})
export class KufangComponent implements OnInit {
  listOfData = [];
  listData = [];
  radioValue = 'All';
  style = {
    display: 'block',
    height: '35px',
    width: '130px',
    lineHeight: '35px',
    padding: '0px 15px'
  };

  workData = [];
  constructor(
    public axios: AxiosService

  ) { }

  ngOnInit(): void {
    this.getalllistdata()

  }
  getalllistdata() {
    this.axios.axiosPost("QueryMaterialSendEx").then((data) => {
      console.log(data)
      if (data["result"] == "ok") {
        this.listOfData = data["order"]
        for (var i = 0; i < this.listOfData.length; i++) {
          // 有没有交期
          if (this.listOfData[i].beiliao_ztai == 3) {
            // 交期<当前时间
            new Date(this.listOfData[i].delivery_date).getTime() > (new Date().getTime()-86400000) ? this.listOfData[i].qx = " " : this.listOfData[i].qx = "delay";
            console.log(new Date(this.listOfData[i].delivery_date).getTime())
          }
        }
      }
    })

    console.log(new Date().getTime())
  }
  doingForm() {
    if (this.radioValue == "All") {
      this.getalllistdata();
    } else if (this.radioValue == "備料中") {
      this.axios.axiosPost("QueryMaterialSendEx", { beiliao_ztai: 1 }).then((data) => {
        console.log(data)
        if (data["result"] == "ok") {
          this.listOfData = data["order"]
        }
      })
    } else if (this.radioValue == "已備料") {
      this.axios.axiosPost("QueryMaterialSendEx", { beiliao_ztai: 2 }).then((data) => {
        console.log(data)
        if (data["result"] == "ok") {
          this.listOfData = data["order"]
        }
      })
    } else {
      this.axios.axiosPost("QueryMaterialSendEx", { beiliao_ztai: 3 }).then((data) => {
        console.log(data)
        if (data["result"] == "ok") {
          this.listOfData = data["order"]
        }
      })
    }
  }
  collapse(item, key) {
    console.log(key)
    console.log(item.expand);
    this.axios.axiosPost("QueryMaterialSendEx", { unionorder: item.union_order }).then((data) => {
      console.log(data)
      if (data["result"] == "ok") {
        this.listData[key] = data["order"]
      }
    })
    console.log(this.listData[key])
    // this.listData[key]=item;
  }

}
